<template>
    <elm-page-tb>
        <template #top>
          <elm-row>
          <elm-ei placeholder="根据员工姓名查询" size="mini" prefix-icon='el-icon-search' style="width:50px;margin:0 10px" v-model="postData.emp_code" clearable></elm-ei>
          <el-date-picker placeholder="根据月份查询" value-format="yyyyMM" size="mini" type="month"  style="width:50px;margin:0 10px" v-model="postData.month" clearable></el-date-picker>
            <div></div>
            <right>
            <el-button-group>
              <el-button icon="el-icon-search" size="mini" @click="tablebinding()">查询</el-button>
              <elm-open-button url="salary_edit" title="新增"  width="900" :data="{status: '0'}" height="700">新增</elm-open-button>
              <el-button size="mini" @click="openExport" title="模板" >模板</el-button>
              <elm-open-button url="salary_import" title="导入"  width="900" :data="{status: '0'}" height="700">导入</elm-open-button>
            </el-button-group>
          </right>
          </elm-row>
        </template>
        <elm-table url="/business/hrm/salary/GetList" v-if="now_user" :post-data="postData" :default-expand-all="true"  :page-size="20">
          <el-table-column prop="uname" label="姓名" align="center" width="150">
          </el-table-column>
<!--          <el-table-column prop="year" label="工资年份" align="center"  width="60"></el-table-column>-->
          <el-table-column prop="month" label="工资月份" align="center"  width="120"></el-table-column>
          <el-table-column prop="word_day" label="工作天数" align="center"  width="60"></el-table-column>
          <el-table-column prop="cope_salary" label="应发工资" align="center" header-align="center"></el-table-column>
          <el-table-column prop="real_salary" label="实付工资" align="center"  width="150"></el-table-column>
          <el-table-column prop="status" label="状态" align="center"  width="120" :formatter="handleStatus"></el-table-column>
          <el-table-column prop="remark" label="备注"></el-table-column>
          <el-table-column fixed="right" label="操作" width="180px" align="center">
            <template v-slot="scope">
              <elm-open-button url="salary_edit" title="编辑" width="900" height="90%" :data="{ model: scope.row }" type="text" v-if="scope.row.create_user==now_user">编辑</elm-open-button>
              <elm-open-button url="salary_edit" title="查看" width="900" height="90%" :data="{ model: scope.row , disable:true }" type="text" v-if="scope.row.create_user!=now_user">查看</elm-open-button>
              <el-button type="text" size="mini" @click="deleteData(scope.row)" v-if="scope.row.create_user==now_user">删除</el-button>
            </template>
          </el-table-column>
        </elm-table>
    </elm-page-tb>

</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      filterText: '',
      postData: { emp_code: null, month: null},
      now_user:''
    }
  },
  async created() {
    this.now_user= await this.get_user_ei();
   // this.postData.emp_code= this.now_user;
  },
  methods: {
    openExport() {
      window.open('/api/business/hrm/salary/ExportSalary?token='+elm.info.token)
    },
    async deleteData(data) {
      await this.delete('/business/hrm/salary/Delete', { id: data.id });
      this.tablebinding();
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
    handleStatus(e) {
      return e.status === '0' ? '未发放' : '已发放';
    }
  }
}
</script>
